package Tests;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import ModelLayer.GroupRecords;
import ModelLayer.RealException;

public class GroupTest {

	private GroupRecords groupRecords = GroupRecords.getInstance();
	

	@Before
	public void setUp() throws Exception {
		groupRecords.createGroup(7, 0.01, 0.04, 0.07);
	}

	@Test
	public void testUpdatePT() throws RealException {
		groupRecords.getGroup(1).setPaymentTerm(6);
		Assert.assertEquals(6, groupRecords.getGroup(1).getPaymentTerm());
	}

	
	@Test
	public void testUpdatePD() throws RealException {
		groupRecords.getGroup(1).setPickUpDiscount(0.1);
		Assert.assertEquals(0.1, groupRecords.getGroup(1).getPickUpDiscount(), 0);
	}
	
	
	@Test
	public void testUpdateCD() throws RealException {
		groupRecords.getGroup(1).setCraftmanDiscount(0.1);
		Assert.assertEquals(0.1, groupRecords.getGroup(1).getCraftmanDiscount(), 0);
	}
	
	
	@Test
	public void testUpdateQD() throws RealException {
		groupRecords.getGroup(1).setQuantityDiscount(0.1);
		Assert.assertEquals(0.1, groupRecords.getGroup(1).getQuantityDiscount(), 0);
	}
	
	@Test
	public void testDelete() throws RealException {
		groupRecords.deleteGroup(1);
		boolean found = true;
		try
		{
			groupRecords.getGroup(1);
		}
		catch (RealException e) 
		{
			found = false;
		}
		Assert.assertFalse(found);		
	}
	
	@Test
	public void testGet() throws RealException {
		Assert.assertNotSame(null, groupRecords.getGroup(1));
	}
}
